package com.ls.pattern.flyweight.poker;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 扑克享元工厂
 */
public class PokerFactory {

    private static final Poker[][] pokers = new Poker[13][4];

    static {
        init();
    }

    public static void init() {
        for (int i = 0; i < 13; i++) {
            for (int j = 0; j < 4; j++) {
                pokers[i][j] = new Poker(SuitsEnum.values()[j], PointEnum.values()[i]);
            }
        }
    }

    public static Poker getPoker(int point, int suit) {
        return pokers[point][suit];
    }

    /**
     * 创建牌堆
     */
    public static List<Poker> createPokers() {
        List<Poker> pokerList = new ArrayList<>();
        for (int i = 0; i < 13; i++) {
            pokerList.addAll(Arrays.asList(pokers[i]));
        }
        return pokerList;
    }

}